<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/Home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 内容卡片区 -->
    <el-card class="box-card">
      <!-- 搜索框 -->
      <el-input
        placeholder="请输入内容"
        v-model="page.query"
        class="input-with-select"
        clearable
        @clear="clearselect"
      >
        <!-- 搜索按钮 -->
        <el-button
          slot="append"
          icon="el-icon-search"
          @click.enter="ordersearch"
        ></el-button>
      </el-input>
      <el-table :data="orderlist" style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <div>
              <el-tag type="success" v-if="scope.row.pay_status !== '0'"
                >已支付</el-tag
              >
              <el-tag type="danger" v-else>未支付</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormater }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div>
              <!-- 编辑地址按钮 -->
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-edit"
                @click="editgood(scope.row)"
              ></el-button>
              <!-- 查看物流进度按钮 -->
              <el-button
                type="success"
                size="mini"
                icon="el-icon-location-outline"
                @click="deletegood(scope.row)"
              ></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.pagenum"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="page.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
      <!-- 编辑收货地址对话框 -->
      <el-dialog title="编辑收货地址" :visible.sync="cityFormVisible">
        <el-form>
          <el-form-item label="省市区/县">
            <!-- 城市级联选择器 -->
            <el-cascader
              v-model="cityform.cvalue"
              :options="citydata"
              :props="props"
              @change="handleChange"
            >
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" label-width="10%">
            <el-input v-model="cityform.xvalue" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cityFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="cityForm">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 物流进度对话框 -->
      <el-dialog title="物流进度" :visible.sync="logisticsVisible" width="30%">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in contexts"
            :key="index"
            :timestamp="activity.time"
          >
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
         
          <el-button type="primary" @click="logisticsVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import citydata from "./citydata.js";
export default {
  data() {
    return {
      contexts:[],//物流地址数组
      logisticsVisible: false, //物流进度对话框开关
      cityFormVisible: false, //编辑收货地址对话框开关
      // 城市数据库
      citydata: citydata,
      // 城市数据对话框数据
      cityform: {
        cvalue: "", //城市级联选择器值
        xvalue: "", //详细地址
      },
      //级联选择器数据规则
      props: {
        expandTrigger: "hover",
      },
      // 订单列表
      orderlist: [],
      page: {
        // 查询参数
        query: "",
        // 当前页码
        pagenum: 1,
        // 每页显示条数
        pagesize: 10,
      },
      // 总条数
      total: 0,
    };
  },
  created() {
    // 获取订单列表
    this.getorderlist();
  },
  methods: {
    // 获取订单列表
    async getorderlist() {
      const { data: res } = await this.$http.get("orders", {
        params: this.page,
      });
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.total = res.data.total;
      this.orderlist = res.data.goods;
      console.log(res);
    },
    // 页面大小回调函数
    handleSizeChange(val) {
      this.page.pagesize = val;
      this.getorderlist();
    },
    // 当前页面
    handleCurrentChange(val) {
      this.page.pagenum = val;
      this.getorderlist();
    },
    // 搜索框清空回调函数
    clearselect() {
      this.getorderlist();
    },
    // 搜索按钮点击事件点击回调函数
    async ordersearch() {
      const { data: res } = await this.$http.get("orders", {
        params: this.page,
      });
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.total = res.data.total;
      this.orderlist = res.data.goods;
      console.log(this.orderlist);
    },
    // 编辑地址按钮点击回调函数
    editgood(order) {
      this.cityFormVisible = !this.cityFormVisible;
      console.log(this.citydata);
    },
    // 级联选择值变化回调函数
    handleChange() {},
    // 编辑收货地址对话框确定提交按钮回调函数
    cityForm() {
      this.cityFormVisible = !this.cityFormVisible;
    },
    // 查看物流按钮点击回调函数
   async deletegood(order) {
      this.logisticsVisible = !this.logisticsVisible;
     const {data:res}=await this.$http.get(`/kuaidi/${1106975712662}`)
     if(res.meta.status!==200) return this.$message.error(res.meta.msg)
     this.contexts=res.data
     console.log(res);
    },
  },
};
</script>

<style scoped>
.input-with-select {
  width: 40%;
}
</style>